package xhwl.insurance.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.trello.rxlifecycle.components.support.RxFragment;
import com.umeng.analytics.MobclickAgent;

import xhwl.insurance.R;
import xhwl.insurance.util.ImmerseUtil;


/**
 * Created by admin on 2016/12/20.
 */

public abstract class BaseFragment extends RxFragment {
    protected FragmentManager manager;
    protected FragmentTransaction transaction;
    protected FragmentActivity mActivity;

    protected TextView titleTextView;
    protected TextView leftTextView;
    protected TextView rightTextView;
    protected ImageView backImageView;
    protected ImageView rightImageView;
    protected LinearLayout llBack;
    protected RelativeLayout titleLayout;


    protected ImmerseUtil immerseUtil;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        mActivity = getActivity();
        manager = mActivity.getSupportFragmentManager();
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initListener();
        processOper();
        loadData();
    }

    protected void initTitleViews(View view) {
        titleLayout= (RelativeLayout) view.findViewById(R.id.title_layout);
        titleTextView = (TextView) view.findViewById(R.id.title_textview);
        rightTextView=(TextView) view.findViewById(R.id.title_right_textview);
        leftTextView=(TextView) view.findViewById(R.id.title_left_textview);
        backImageView = (ImageView) view.findViewById(R.id.title_left_imageview);
        rightImageView = (ImageView) view.findViewById(R.id.title_right_imageview);

        llBack = (LinearLayout) view.findViewById(R.id.llBack);
        llBack.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                getActivity().onBackPressed();
            }
        });
        setUpTitleView();
        if (isImmerseLayout()) {

            if(titleLayout!=null){
                immerseUtil=new ImmerseUtil(this);
                immerseUtil.setImmerseLayout(titleLayout);
            }
        }
    }
    protected boolean isImmerseLayout() {
        return true;
    }
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("MainScreen"); //统计页面，"MainScreen"为页面名称，可自定义
    }
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("MainScreen");
    }
    protected abstract void initView(View view);

    protected void setUpTitleView() {
    };

    protected abstract void initListener();

    protected abstract void loadData();

    protected void processOper(){};
}

